import axiosInstance from './axiosInstance.js';
/**
 * 获取首页数据
 * url: /
 * method: get
 * @returns 首页数据
 */
export const getHomeData = async () => {
    const response = await axiosInstance.get('/');
    return response as any;
}
/**
 * 用户登录
 * url: /account/login
 * method: post
 * @param username 用户名
 * @param password 密码
 * @returns 用户信息
 */
export const login = async (username: string, password: string) => {

    const response = await axiosInstance.post('/account/login', {
      username,
      password,
    });
    return response as any;

}

/**
 * 注销登录
 * url: /account/logout
 * method: post
 * @returns void
 */
export const logout = async () => {
    const response = await axiosInstance.post('/account/logout');
    return response as any;
}

/**
 * 注册新用户
 * url: /account/register
 * method: post
 * @param username 用户名
 * @param password 密码
 * @returns 用户信息
 */
export const register = async (username: string, password: string) => {
    const response = await axiosInstance.post('/account/register', {
        username,
        password,   
    })
    return response as any;
}

/**
 * 获取用户列表
 * url: /users 
 * method: get
 * @param page 页码
 * @param username 标题
 * @returns 用户列表
 */
export const getUsers = async (page: number = 1, username: string = '') => {
    const response = await axiosInstance.get('/users', {
        params: {
            page,
            username,
        }
    })
    return response as any;
}

/**
 * 获取当前用户信息
 * url: /account
 * method: get
 * @returns 用户信息
 */
export const getCurrentUser = async () => {
    const response = await axiosInstance.get('/account');
    return response as any;
}
/**
 * 修改当前用户信息
 * url: /account
 * method: put
 * @param username 用户名
 * @param password 密码
 * @param description 描述
 * @returns 用户信息
 */
export const updateCurrentUser = async (username: string, password: string, description: string = '') => {
    const response = await axiosInstance.put('/account', {
        username,
        password,
        description,
    })
    return response as any;
}